package cn.funeralobjects.aoss.utils;

import cn.funeralobjects.ams.web.api.ProductApiApi;
import cn.funeralobjects.utils.aliyun.core.model.AliyunAction;
import cn.funeralobjects.utils.aliyun.oss.AliyunOssClient;
import cn.funeralobjects.utils.aliyun.oss.AliyunOssClientFactory;
import reactor.core.publisher.Mono;

/**
 * @author FuneralObjects
 * Create date: 2020/6/7 10:18 AM
 */
public class OssApiUtils {

    /**
     * 创建oss客户端
     *
     * @param prodResCode   资源编码
     * @param action        访问行动
     * @param productApiApi 产品api
     * @return 客户端
     */
    public static Mono<AliyunOssClient> createOssClient(String prodResCode, AliyunAction action, ProductApiApi productApiApi) {
        return productApiApi.getExistsAccessKey(prodResCode, action.getAction(), action.getVersion())
                .map((vProductResAccessKey) -> new AliyunOssClientFactory(action.getDomain(), vProductResAccessKey.getAccessKeyId(), vProductResAccessKey.getAccessKeySecret()).createClient(vProductResAccessKey.getRegionId()));
    }
}
